package array;

/**
 * @description: 704. 二分查找
 * https://leetcode.cn/problems/binary-search/
 * @author: caoyihong
 * @date: 2025-10-09 09:55
 * @Version 1.0
 **/
public class BinarySearch {
    public static void main(String[] args) {
        String[] inputs = args[0].substring(1,args[0].length()-1).split(",");
        int[] nums = new int[inputs.length];
        for (int i = 0; i < inputs.length; i++) {
            nums[i] = Integer.parseInt(inputs[i]);
        }
        int target = Integer.parseInt(args[1]);

        int i = 0,j = nums.length-1;
        while (i <= j) {
            int mid = (i+j)/2;
            if (nums[mid] > target) {
                j = mid - 1;
            } else if (nums[mid] < target) {
                i = mid + 1;
            } else {
                System.out.println(mid);
                return;
            }
        }
        System.out.println(-1);
    }
}
